function res = resid_dim5teaser_pscc(x,la,u,mu0,phi,kap0,eta0,be,del,d,Pzz,cz)
%function solving for equilibrium (given lambda) with teaser pricing

options = optimoptions('fsolve','TolFun',1e-9,'TolX',1e-9,'StepTolerance',1e-9,'Display','none');

shat_1=x(1);shat_2=x(2);shat_3=x(3);shat_4=x(4);shat_5=x(5);dim=5;

%solve for theta's corresponding to shat's
th_1=(kap_s_pscc(shat_1,kap0,phi)/la)^(1/(1+eta0));
th_2=(kap_s_pscc(shat_2,kap0,phi)/la)^(1/(1+eta0));
th_3=(kap_s_pscc(shat_3,kap0,phi)/la)^(1/(1+eta0));
th_4=(kap_s_pscc(shat_4,kap0,phi)/la)^(1/(1+eta0));
th_5=(kap_s_pscc(shat_5,kap0,phi)/la)^(1/(1+eta0));

%match surpluses given active selling behavior
S_1=kap_s_pscc(shat_1,kap0,phi)/eta_pscc(th_1,mu0,eta0)+la/mu_pscc(th_1,mu0,eta0);
S_2=kap_s_pscc(shat_2,kap0,phi)/eta_pscc(th_2,mu0,eta0)+la/mu_pscc(th_2,mu0,eta0);
S_3=kap_s_pscc(shat_3,kap0,phi)/eta_pscc(th_3,mu0,eta0)+la/mu_pscc(th_3,mu0,eta0);
S_4=kap_s_pscc(shat_4,kap0,phi)/eta_pscc(th_4,mu0,eta0)+la/mu_pscc(th_4,mu0,eta0);
S_5=kap_s_pscc(shat_5,kap0,phi)/eta_pscc(th_5,mu0,eta0)+la/mu_pscc(th_5,mu0,eta0);

%match surpluses given behavior across states
S_vec=u*ones(dim,1)-cz+be*(1-d)*(1-del)*(-la*ones(dim,1)+Pzz(:,1)*(-kap_n_pscc(shat_1,kap0,phi)+S_1)+Pzz(:,2)*(-kap_n_pscc(shat_2,kap0,phi)+S_2)+Pzz(:,3)*(-kap_n_pscc(shat_3,kap0,phi)+S_3)+Pzz(:,4)*(-kap_n_pscc(shat_4,kap0,phi)+S_4)+Pzz(:,5)*(-kap_n_pscc(shat_5,kap0,phi)+S_5));

%equilibrium consistency conditions for surplus
res= [S_1;S_2;S_3;S_4;S_5]-S_vec(1:5);
end